package cn.momoshenchi.controller;

import cn.momoshenchi.ResultInfo;
import cn.momoshenchi.pojo.StudentGpa;
import cn.momoshenchi.pojo.StudentResume;
import cn.momoshenchi.service.StudentGpaService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * @version : 1.0
 * @author: momoshenchi
 * @date: 2021/5/18 - 14:09
 */
@Controller
@Api("学生绩点信息")
public class StudentGpaController
{
    @Autowired
    private StudentGpaService studentGpaService;

    public  ResultInfo success()
    {
        return  new ResultInfo();
    }

    @GetMapping("studentGpa")
    public String page()
    {
        return  "/view/studentGpa.html";
    }


    @Operation(summary="添加学生绩点")
    @PostMapping("studentGpa")
    @PreAuthorize("hasAuthority('student:add')")
    @ResponseBody
    public ResultInfo add(@Valid @RequestBody StudentGpa studentGpa)
    {
        studentGpaService.insertGpa(studentGpa);
        return  success();
    }
    @Operation(summary="修改学生绩点")
    @PreAuthorize("hasAuthority('student:update')")
    @PutMapping("studentGpa")
    @ResponseBody
    public ResultInfo update( @RequestBody StudentGpa studentGpa)
    {
        studentGpaService.updateGpaById(studentGpa);
        return  success();
    }

    @Operation(summary="通过主键删除学生绩点")
    @DeleteMapping("studentGpa/{id}")
    @PreAuthorize("hasAuthority('student:delete')")
    @ResponseBody
    public ResultInfo delete(@PathVariable  Integer id)
    {
        return  success();
    }

    @Operation(summary="列表查询学生绩点")
    @GetMapping("studentGpa/list")
    @ResponseBody
    public ResultInfo  selectList(int page,int size)
    {
        IPage<StudentGpa> page1=new Page<StudentGpa>();
        page1.setPages(page);
        page1.setSize(size);
        page1 = studentGpaService.getList(page1);
        ResultInfo resultInfo=new ResultInfo();
       resultInfo.setResult(page1.getRecords());
       return  resultInfo;
    }

    @Operation(summary="通过Id查询学生绩点")
    @GetMapping("studentGpa/{id}")
    @ResponseBody
    public ResultInfo  selectById(@PathVariable Integer id)
    {
        StudentGpa serviceById = studentGpaService.getGpaById(id);
        ResultInfo resultInfo=new ResultInfo();
        resultInfo.setResult(serviceById);
        return  resultInfo;
    }
}
